<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goods-edit" th:object="${goods}" >
            <input name="id" id="id" th:field="*{id}" type="hidden">
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">条码：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="barCode" th:field="*{barCode}" class="form-control" type="text" >-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">品牌：</label>
                <div class="col-sm-8">
                    <input name="brand" id="brand" th:field="*{brand}" class="form-control" type="text">
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">尺码：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="size" th:field="*{size}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">尺码：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="size2" th:field="*{size2}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label  is-required">款号：</label>
                <div class="col-sm-8">
                    <input name="styleNumber" id="styleNumber" th:field="*{styleNumber}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">吊牌价：</label>
                <div class="col-sm-8">
                    <input name="tagPrice" id="tagPrice" th:field="*{tagPrice}" class="form-control" type="number" required>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">优惠价：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="primeCost" id="primeCost" th:field="*{preferentialPrice}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">面料成分：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="fabricContent"  class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位：</label>
                <div class="col-sm-8">
                    <!--<input name="unit" th:field="*{unit}" class="form-control" type="text">-->
                    <select class="form-control" name="unit" th:field="*{unit}">
                        <option value="1">件</option>
                        <option value="2">套</option>
                        <option value="3">条</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">商品名称：</label>
                <div class="col-sm-8">
                    <input name="name" id="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file" value="">
                    <input id="imgPath" type="hidden" name="imgPath" th:field="*{imgPath}">
                    <img src="" id="previewImg" width="64px" height="64px">
                </div>
            </div>




        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "goods/goods";
        $("#form-goods-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                var formData = new FormData();
                if ($('#filePath')[0].files[0] != null) {
                    formData.append('fileName', $("#fileName").val());
                    formData.append('file', $('#filePath')[0].files[0]);
                }
                formData.append("id",$("#id").val());

                formData.append('brand',$("#brand").val());
                formData.append('tagPrice',$("#tagPrice").val());
                formData.append('unit',$("#unit").val());
                formData.append('name',$("#name").val());
                formData.append('styleNumber',$("#styleNumber").val());
                formData.append("imgPath",$("#imgPath").val());

                console.log("formData:"+JSON.stringify(formData))
                $.ajax({
                    url: prefix + "/edit",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false, // 告诉jQuery不要去处理发送的数据
                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                    dataType: "json",
                    success: function(result) {
                        console.log("result:"+result)
                        $.operate.successCallback(result);
                    }
                });

                //$.operate.save(prefix + "/edit", $('#form-goods-edit').serialize());
            }
        }

        $(function (){
            var imgPath=$("#imgPath").val();
            var _pre = ctx + "common/download/resource?resource=" + imgPath;
            $("#previewImg").attr("src",_pre);
        });

    </script>
</body>
</html>